@ECHO OFF


SETLOCAL
CALL .\env.bat
SET PROJECT_DIR=.\..\..
SET CLIENT_CLASSDIR=%PROJECT_DIR%\build\client\classes
SET SERVER_CLASSDIR=%PROJECT_DIR%\build\server\classes
SET RUN_CLIENT_CLASSPATH=%WASP_HOME%\lib\wasp.jar;%CLIENT_CLASSDIR%
SET RUN_SERVER_CLASSPATH=%WASP_HOME%\lib\wasp.jar;%WASP_HOME%\lib\persistent_store.jar;%WASP_HOME%\lib\persistent_store_ifaces.jar;%WASP_HOME%\lib\wsrm_ifaces.jar;%WASP_HOME%\lib\wsrm.jar;;%SERVER_CLASSDIR%
SET RUN_J2EE_CLIENT_CLASSPATH=%J2EE_CLASSPATH%;%WASP_CLASSPATH%;%RUN_CLIENT_CLASSPATH%
SET COMPILE_CLIENT_CLASSPATH=%COMPILE_WITH_WASP_CLASSPATH%;%CLIENT_CLASSDIR%
SET COMPILE_SERVER_CLASSPATH=%COMPILE_WITH_WASP_CLASSPATH%;%SERVER_CLASSDIR%
SET DEMO_DIRNAME=basic/employeedb





GOTO :helpok
:help

ECHO.
ECHO     Description: This is simple 'Employee DB!' demo
ECHO.
ECHO     Runtime usage:
ECHO       make_server      compiles service and server sources
ECHO       run_server       runs server and publishes service
ECHO       make_client      makes client classes
ECHO       run_client       runs client
ECHO.
ECHO     Deployment usage:
ECHO       make_service     compiles service sources
ECHO       deploy_service   deploys service classes on to Systinet Server
ECHO       make_client      makes client classes
ECHO       run_client       runs client
ECHO       undeploy_service undeploys service package from Systinet Server
ECHO.
ECHO     Specific client usage:
ECHO       spy_client       runs the client with SOAPSpy related properties
ECHO       run_jms_client   runs the client over JMS queue
ECHO.
ECHO     clean              removes build directory

GOTO :EOF
:helpok


GOTO :make_serviceok
:make_service

if %errorlevel%==5 goto :EOF
REM Let's compile service sources at first.
ECHO Compiling service java sources...
MKDIR %SERVER_CLASSDIR%
"%JAVA_HOME%\bin\javac" -sourcepath %PROJECT_DIR% -d %SERVER_CLASSDIR% src\demo\basic\employeedb\server\EmployeeDBService.java 


GOTO :EOF
:make_serviceok


GOTO :make_serverok
:make_server

if %errorlevel%==5 goto :EOF
REM Let's make server sources.
ECHO Compiling server java sources...
MKDIR %SERVER_CLASSDIR% 
"%JAVA_HOME%\bin\javac" -classpath "%COMPILE_SERVER_CLASSPATH%" -sourcepath %PROJECT_DIR% -d %SERVER_CLASSDIR% src\demo\basic\employeedb\server\EmployeeDBServer.java 


GOTO :EOF
:make_serverok


GOTO :run_serverok
:run_server

if %errorlevel%==5 goto :EOF
REM Server class is ready, let's try to run it.
ECHO Running server...
REM start "Systinet Server" "%JAVA_HOME%\bin\java" "-Dsystinet.demo.server.url=%SERVER_URL%" "-Didoox.debug.level=1" -cp "%RUN_SERVER_CLASSPATH%" demo.basic.employeedb.server.EmployeeDBServer 
"%JAVA_HOME%\bin\java" "-Dsystinet.demo.server.url=%SERVER_URL%" "-Didoox.debug.level=3" -cp "%RUN_SERVER_CLASSPATH%" demo.basic.employeedb.server.EmployeeDBServer 


GOTO :EOF
:run_serverok


GOTO :deploy_serviceok
:deploy_service

if %errorlevel%==5 goto :EOF
REM We're going to deploy compiled service on to running Systinet Server.
ECHO Deploying service...
CALL Deploy --uri /demo/basic/EmployeeDB --class demo.basic.employeedb.server.EmployeeDBService -t %SERVER_URL% --package http://systinet.com/package/demo/basic/employeedb/server:EmployeeDBDemo --redeploy --classpath "%SERVER_CLASSDIR%" 


GOTO :EOF
:deploy_serviceok


GOTO :undeploy_serviceok
:undeploy_service

if %errorlevel%==5 goto :EOF
REM Service package will have been undeployed from server.
ECHO Undeploying service...
CALL Undeploy --package http://systinet.com/package/demo/basic/employeedb/server:EmployeeDBDemo --target %SERVER_URL% 


GOTO :EOF
:undeploy_serviceok


GOTO :make_clientok
:make_client

if %errorlevel%==5 goto :EOF
REM Let's make client classes now.
ECHO Compiling WSDL to Java source...
CALL WSDL2Java --output-directory %PROJECT_DIR%\build\src --url %SERVER_URL%/demo/basic/EmployeeDB/wsdl --force 

ECHO Compiling stubs...
MKDIR %CLIENT_CLASSDIR% 
"%JAVA_HOME%\bin\javac" -classpath "%COMPILE_WITH_WASP_CLASSPATH%" -sourcepath %PROJECT_DIR%\build\src -d %CLIENT_CLASSDIR% .\build\src\demo\basic\employeedb\client\EmployeeDB.java 

ECHO Compiling client...
"%JAVA_HOME%\bin\javac" -classpath "%COMPILE_CLIENT_CLASSPATH%" -sourcepath %PROJECT_DIR% -d %CLIENT_CLASSDIR% .\src\demo\basic\employeedb\client\EmployeeDBClient.java 


GOTO :EOF
:make_clientok


GOTO :run_clientok
:run_client

if %errorlevel%==5 goto :EOF
REM Client class is ready, let's try to run it.
ECHO Running client...
"%JAVA_HOME%\bin\java" "-Dsystinet.demo.server.url=%SERVER_URL%" -cp "%RUN_CLIENT_CLASSPATH%" demo.basic.employeedb.client.EmployeeDBClient 


GOTO :EOF
:run_clientok


GOTO :spy_clientok
:spy_client

if %errorlevel%==5 goto :EOF
REM Client class is ready, let's try to spy it.
ECHO Spy client...
"%JAVA_HOME%\bin\java" "-Dhttp.proxyHost=%PROXY_HOST%" "-Dhttp.proxyPort=%PROXY_PORT%" "-Dhttp.nonProxyHosts=" "-Dsystinet.demo.server.url=%SERVER_URL%" -cp "%RUN_CLIENT_CLASSPATH%" demo.basic.hello.client.HelloClient 


GOTO :EOF
:spy_clientok


GOTO :run_jms_clientok
:run_jms_client

if %errorlevel%==5 goto :EOF
REM Client class is ready, let's try to run it over JMS queue.
ECHO Running client over JMS queue...
"%JAVA_HOME%\bin\java" "-Dsystinet.demo.server.url=%URL_JMS_QUEUE%" "-Didoox.debug.logger=waspLogger" -cp "%RUN_J2EE_CLIENT_CLASSPATH%" demo.basic.hello.client.HelloClient 


GOTO :EOF
:run_jms_clientok


GOTO :cleanok
:clean

rmdir /S /Q .\build 

GOTO :EOF
:cleanok



IF NOT "%1" == "" CALL :%*
IF "%1" == "" CALL :help




